﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wpf.CommonTools.SystemExtension;

namespace Convertor
{
    /// <summary>
    /// RenameWindow.xaml 的交互逻辑
    /// </summary>
    public partial class RenameWindow : Window
    {
        private TemplateToSaveContainer templateContainer;

        public TemplateToSaveContainer TemplateContainer
        {
            get { return templateContainer; }
        }

        public RenameWindow(TemplateToSaveContainer templateContainer)
        {
            InitializeComponent();
            this.templateContainer = templateContainer;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        }

        private bool close;
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (Config.GlobalConfig.EnableEscToCloseChildWindows && this.IsActive && e.Key == Key.Escape)
            {
                close = true;
            }
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (close && Config.GlobalConfig.EnableEscToCloseChildWindows && this.IsActive && e.Key == Key.Escape)
            {
                this.Close();
            }
        }

        private void Button_OK_Click(object sender, RoutedEventArgs e)
        {
            var a = Config.GlobalConfig.TemplateList.Where(k => k.Name == templateContainer.Name).FirstOrDefault();
            if (a != null)
            {
                this.DialogResult = false;
            }
            else
            {
                templateContainer.Path = System.IO.Path.Combine(Config.GlobalConfig.WorkspacePath, templateContainer.Name + @".cvt1");
                this.DialogResult = true;
            }

            this.Close();
        }

        private void Button_Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

    }
}
